package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.RelateHeaderData;
import com.tenglong.teacher.ui.adapter.viewholder.RelateCradeOrScourseViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.List;

public class RelateScourseAdapter extends RecyclerView.Adapter<BaseViewHolder<RelateHeaderData.ScourseName>> {

    private List<RelateHeaderData.ScourseName> scourseNames;
    private RelateScourseListener listener;

    public RelateScourseAdapter(List<RelateHeaderData.ScourseName> scourseNames) {
        this.scourseNames = scourseNames;
    }

    @NonNull
    @Override
    public BaseViewHolder<RelateHeaderData.ScourseName> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new RelateCradeOrScourseViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.date_type_item_layout, parent, false), listener);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<RelateHeaderData.ScourseName> holder, int position) {
        holder.setLayoutInfo(scourseNames.get(position));
    }

    @Override
    public int getItemCount() {
        return scourseNames.size();
    }

    public RecyclerView.Adapter setRelateScourseListener(RelateScourseListener listener) {
        this.listener = listener;
        return this;
    }

    public interface RelateScourseListener {
        void onRelateScourseListener(RelateHeaderData.ScourseName info, int position);
    }
}
